// pages/qualityControl/executeControl/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    array3: [],
    value3:0,
    allData:[],
    now:"",
    nowData:[],
    dateResouse:[],
    monthResouse:[],
    quarterResouse:[],
    yearResouse:[],
    date:"",
    items: [
      { name: '1', value: 'standard is dealt for u.' },
      { name: '2', value: 'standard is dealicient for u.', checked: 'true' },
  ]
  },
  bindDateChange: function (e) {
    this.setData({
        date: e.detail.value
    })
},
getequiment(){
  this
  .axios
  .custom("AllInstalledProducts", "serialOrLotNumbers", {
    id: this.Store.getItem("userid"),
  })
  .then((result) => {
    console.log(result);
    this.setData({
      array3:result.data
    })
    this.equipChange()
    
  })
  .catch((err) => {
    self.$notify(err.data.msg, "error");
  });
},
toadd(e){
  let self = this
  if(self.data.date==""){
    wx.showToast({
      title: '请选择时间',
      icon: 'error',
      duration: 2000
    })
    return
  }
  //const { item } = this.data.dateResouse.concat(this.data.monthResouse,this.data.quarterResouse,this.data.yearResouse)
  let arrList =this.data.dateResouse.concat(this.data.monthResouse,this.data.quarterResouse,this.data.yearResouse)
  if(arrList.length<1){
    wx.showToast({
      title: '请选择质控项',
      icon: 'error',
      duration: 2000
    })
    return
  }
  console.log(this.data.dateResouse.concat(this.data.monthResouse,this.data.quarterResouse,this.data.yearResouse))
  let that = this;
  // 当传递的数据过多的时候 使用eventChannel的方式来传值

  wx.navigateTo({
    url: './addQuality/index',
        success:function(res){
         res.eventChannel.emit('toaddqua',{item:arrList,allData:self.data.allData,code:self.data.array3[self.data.value3],date:self.data.date})
  }
})
}
,
checkboxChangeOne: function (e) {
  console.log('checkbox发生change事件，携带value值为：', e.detail.value)
  this.data.dateResouse = e.detail.value
},
checkboxChangeTwo: function (e) {
  console.log('checkbox发生change事件，携带value值为：', e.detail.value)
  this.data.monthResouse = e.detail.value
},
checkboxChangeThree: function (e) {
  console.log('checkbox发生change事件，携带value值为：', e.detail.value)
  this.data.quarterResouse = e.detail.value
},
checkboxChangeFour: function (e) {
  console.log('checkbox发生change事件，携带value值为：', e.detail.value)
  this.data.yearResouse = e.detail.value
},
bindPicker3Change: function(e) {
  this.setData({
      value3: e.detail.value
  })
  this.equipChange()
},
    // 选择设备编号加载数据
    equipChange() {
      let self = this;
        self
          .axios
          .query("QcProjectCategoryInformation", {}, { code: self.data.array3[self.data.value3] })
          .then((result) => {
            console.log(result);
            let obj={
              data:[],
              month:[],
              quarter:[],
              year:[]
            }
            result.data.rows.forEach(e=>{
              e.checked = false
                if(e.parentId=='日检'){
                    obj.data.push(e)
                }else if(e.parentId=='月检'){
                  obj.month.push(e)
                }else if(e.parentId=='季检'){
                  obj.quarter.push(e)
                }else if(e.parentId=='年检'){
                  obj.year.push(e)
                }
            })
            this.setData({
              nowData:obj
            })
            console.log(obj);

          })
          .catch((err) => {
            self.$notify(err.data.msg, "error");
          });
        self
          .axios
          .query("QcProjectList", {}, { code: self.data.array3[self.data.value3]})
          .then((result) => {
            this.setData({
              allData:result.data.rows
            })
          })
          .catch((err) => {
            self.$notify(err.data.msg, "error");
          });
    },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR - 140;
        console.log(calc)
        that.setData({
          winHeight: calc
        });
      }
    });
    this.getequiment()
    this.setData({
      now:this.getTime(new Date())
    })
  },
  getTime(time){
    let str = new Date(time);
    let year = str.getFullYear()
    let month = (str.getMonth()+1)<10?0+""+(str.getMonth()+1):(str.getMonth()+1)
    let date = str.getDate()<10?0+""+str.getDate():str.getDate()
    return year+'-'+month+'-'+date

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})